package vip.xumy.core.golbal;

import java.io.File;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

@Component
public class GlobalConstant {
	
	public static String RESOURCES_ROOT_PATH;
	public static String FILE_DOWNLOAD_PATH;
	
	public static final String DEFAULT_PASSWORD = DigestUtils.md5DigestAsHex("888888".getBytes());
	public static final String CODE_KEY_PREFIX = "login-code-";
	public static final String TIKEN_KEY_PREFIX = "login-token-";
	public static final String LOGIN_COOKIE_NAME = "UMLoginToken";
	
	public static final String ENCODING_UTF8 = "UTF-8";
	
	@Value("${service.package.type:war}")
	public void setPackageType(String type) {
		if("jar".equals(type)) {
			ApplicationHome h = new ApplicationHome(GlobalConstant.class);
	        File jarF = h.getSource();
	        RESOURCES_ROOT_PATH = jarF.getParentFile().toString();
		}else {
			RESOURCES_ROOT_PATH = GlobalConstant.class.getClassLoader().getResource("").getPath();
		}
		FILE_DOWNLOAD_PATH = RESOURCES_ROOT_PATH + "/file/";
	}
	
}
